#include <bits/stdc++.h>

using namespace std;

int t;
int n;
int a[200005];
long long pre[200005];
long long dp[2005][2005];

int main() {
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	for (cin >> t; t--; ) {
		cin >> n;
		for (int i = 1; i <= n; i++)
			cin >> a[i], dp[i][0] = pre[i] = pre[i - 1] + (a[i - 1] == a[i] ? a[i] : 0);
		for (int i = 2; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				dp[i][j] = 0;
				for (int k = 0; k < j; k++)
					dp[i][j] = max(dp[i][j], dp[j][k] + (a[k] == a[j + 1] ? a[j + 1] : 0) + (pre[i] - pre[j] - (a[j] == a[j + 1] ? a[j] : 0)));
			}
		}
		cout << *max_element(dp[n], dp[n] + n) << '\n';
	}
	return 0;
}
